package com.bs.blogspace.mapper;

import com.bs.blogspace.pojo.AddSpace;
import com.bs.blogspace.pojo.Space;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
public interface AddSpaceMapper {
    //加入空间
    @Insert("insert into add_space(phone,space_id,join_time,create_time,update_time)" +
            "VALUES (#{phone},#{spaceId},#{joinTime},#{createTime},#{updateTime})")
    void joinSpace(AddSpace addSpace);
    //根据手机和ID查询是否加入
    @Select("select * from add_space where phone=#{phone} and space_id=#{spaceId}")
    AddSpace query(AddSpace addSpace);

    /*查看指定用户已加入的空间*/
    @Select("select space_name,space_id from space where space_id in (select space_id from add_space where phone=#{phone})")
    List<AddSpace> queryUserAddSpace(String phone);

    /*退出空间*/
    @Delete("delete  from add_space where space_id=#{spaceId} and phone=#{phone}")
    boolean exitSpace(AddSpace addSpace);
}
